package com.example.demo6.demos.controller;

import com.example.demo6.demos.controller.request.FavoriteRequest;
import com.example.demo6.demos.service.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class FavoriteController {

    @Autowired
    private FavoriteService favoriteService;

    @PostMapping("/add-to-favorites")
    public ResponseEntity<String> addToFavorites(@RequestBody FavoriteRequest favoriteRequest) {
        try {
            favoriteService.addToFavorites(favoriteRequest.getUserId(), favoriteRequest.getProductId());
            return new ResponseEntity<>("Successfully added to favorites.", HttpStatus.OK);
        } catch (Exception e) {
            return new ResponseEntity<>("Failed to add to favorites: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
}
